{include file="public/header"}
<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .layui-form-item {
        margin-right: 30%;
    }
</style>
</head>

<body>
    <div class="cBody">
        <form id="addForm" class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">菜单名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-block">
                    <select name="parent_id">
                        <option value="0">顶级菜单</option>
                        {volist name="list" id="v"}
                        {if $v['level']==0}
                        {if $v['controller']!=''}
                        <option value="{$v.id}" disabled>{$v.name}</option>
                        {else/}
                        <option value="{$v.id}">{$v.name}</option>
                        {/if}
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" name="ico" id="ico" class="layui-input">
                </div>
                <a href="javascript:;" class="layui-btn layui-btn-primary"
                    onclick="OpenView('{:url('Index/icon')}','图标选择')">图标选择</a>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">控制器</label>
                <div class="layui-input-block">
                    <select name="controller" lay-filter="controller">
                        <option value="">请选择</option>
                        {foreach $controller as $k=>$v }
                        <option value="{$v.controller}">{$v.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">方法</label>
                <div class="layui-input-block">
                    <select name="action" id="action">

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">显示/隐藏</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_show" value="1" title="显示" checked>
                    <input type="radio" name="is_show" value="0" title="隐藏">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <input type="text" name="desc" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submitBut">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

        <script>
            //表单提交
            layui.use(['form', 'layer'], function () {
                var form = layui.form;
                var layer = layui.layer;
                form.render();
                form.on('select(controller)', function (data) {
                    if (data.value != '') {
                        $.ajax({
                            url: '?actions=' + data.value,
                            type: 'GET',
                            dataType: 'json',
                            success: function (res) {
                                // console.log(res.data);
                                var html = '';
                                $.each(res.data, function (v, i) {
                                    html = html + '<option value="' + i.actions + '">' + i.name + '</option>';
                                });
                                $('#action').html(html);
                                form.render();//表单重新渲染
                            }
                        });
                    } else {
                        $('#action').html('');
                        form.render();//表单重新渲染
                    }
                });
                //监听提交
                form.on('submit(submitBut)', function (data) {
                    ajax_submit(data.field, '');
                    return false;
                });
            });
        </script>
    </div>
</body>
{include file="public/footer"}